import javax.swing.plaf.InsetsUIResource;
import java.util.*;


public class Leetcode442 {
    public List<Integer> findDuplicates(int[] nums) {
        List<Integer> res = new ArrayList<>();
        for (int num : nums) {
            int numAbs = Math.abs(num);
            if (nums[numAbs - 1] > 0) {
                nums[numAbs - 1] = -nums[numAbs - 1];
                continue;
            }

            res.add(numAbs);
        }

        return res;
    }
}

